#!/usr/bin/php -q
<?
// ======================================
// Run this script from webcp 0.5.1 in the /web directory
// Make sure you configured config.php first
// ======================================
require("config.inc.php");
if (!@mysql_connect($cfg['dbhost'], $cfg['dbuser'], $cfg['dbpass'])) {
	sleep(1);
	@mysql_connect($cfg['dbhost'], $cfg['dbuser'], $cfg['dbpass']) 
		OR die("Error:  Could not connect to database server");
}
@mysql_select_db($cfg['dbname'])
	OR die("Error:  Could not select database");
// Run from root only
if (posix_getuid() != 0)
	die("This program must be run as root.\n");
	
echo $table = 'subdomains';
echo " make symlinks\n";
$dbp = mysql_query("SELECT * FROM domains WHERE type='subdomain'");
while($data = mysql_fetch_array($dbp)) {
	$gid = "g".$data['owner'];
	symlink($cfg['webdir']."/".$data['owner'], $cfg['webdir']."/".$data['id']);
}
echo "\n..done\n\n";
?>